﻿// IICCheckDlg.cpp: 实现文件
//

#include "pch.h"
#include "ProjectAA.h"
#include "IICCheckDlg.h"
#include "afxdialogex.h"


// CIICCheckDlg 对话框

IMPLEMENT_DYNAMIC(CIICCheckDlg, CDialogEx)

CIICCheckDlg::CIICCheckDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_IIC_CHECK, pParent)
	, CheckFlag(FALSE)
	, RegAdd(_T(""))
	, SlaveAdd(_T(""))
	, LocalVer0(_T(""))
	, LocalVer1(_T(""))
	, LocalVer2(_T(""))
	, LocalVer3(_T(""))
{

}

CIICCheckDlg::~CIICCheckDlg()
{
}

void CIICCheckDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Check(pDX, IDC_CHECK1, CheckFlag);
	DDX_Text(pDX, IDC_CHECK_FW_REG_ADD, RegAdd);
	DDX_Text(pDX, IDC_CHECK_FW_SLAVE_ADD, SlaveAdd);
	DDX_Text(pDX, IDC_LOCAL_FV, LocalVer0);
	DDX_Text(pDX, IDC_LOCAL_FV2, LocalVer1);
	DDX_Text(pDX, IDC_LOCAL_FV3, LocalVer2);
	DDX_Text(pDX, IDC_LOCAL_FV4, LocalVer3);
}


BEGIN_MESSAGE_MAP(CIICCheckDlg, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON2, &CIICCheckDlg::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON1, &CIICCheckDlg::OnBnClickedButton1)
END_MESSAGE_MAP()


// CIICCheckDlg 消息处理程序


BOOL CIICCheckDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	ReadConfigIni();
	gSystemMgr.m_ptrIICCheckUI = this;

	return TRUE;
}


void CIICCheckDlg::OnCancel()
{

	CDialogEx::OnCancel();
}


void CIICCheckDlg::OnBnClickedButton2()
{
	SaveEditValueToConfig();
}


void CIICCheckDlg::ReadConfigIni()
{
	CheckFlag = gSystemMgr.check_on;
	RegAdd = gSystemMgr.FW_regAdd;
	SlaveAdd = gSystemMgr.FW_SlaveAdd;
	LocalVer0 = gSystemMgr.LocalVer[0];
	LocalVer1 = gSystemMgr.LocalVer[1];
	LocalVer2 = gSystemMgr.LocalVer[2];
	LocalVer3 = gSystemMgr.LocalVer[3];

	UpdateData(FALSE);
}

void CIICCheckDlg::SaveEditValueToConfig()
{
	UpdateData(TRUE);
	gSystemMgr.check_on = CheckFlag;
	gSystemMgr.FW_regAdd = RegAdd;
	gSystemMgr.FW_SlaveAdd = SlaveAdd;
	gSystemMgr.LocalVer[0] = LocalVer0;
	gSystemMgr.LocalVer[1] = LocalVer1;
	gSystemMgr.LocalVer[2] = LocalVer2;
	gSystemMgr.LocalVer[3] = LocalVer3;

	CString cstr;
	cstr.Format(L"%d", gSystemMgr.check_on); gSystemMgr.m_cIICCheckConfigIni.SaveConfigIni(L"IICCheck", L"check_on", cstr);

	gSystemMgr.m_cIICCheckConfigIni.SaveConfigIni(L"IICCheck", L"FW_regAdd", gSystemMgr.FW_regAdd);
	gSystemMgr.m_cIICCheckConfigIni.SaveConfigIni(L"IICCheck", L"FW_SlaveAdd", gSystemMgr.FW_SlaveAdd);
	gSystemMgr.m_cIICCheckConfigIni.SaveConfigIni(L"IICCheck", L"SNAddr", gSystemMgr.SNAddr);
	gSystemMgr.m_cIICCheckConfigIni.SaveConfigIni(L"IICCheck", L"LocalVer[0]", gSystemMgr.LocalVer[0]);
	gSystemMgr.m_cIICCheckConfigIni.SaveConfigIni(L"IICCheck", L"LocalVer[1]", gSystemMgr.LocalVer[1]);
	gSystemMgr.m_cIICCheckConfigIni.SaveConfigIni(L"IICCheck", L"LocalVer[2]", gSystemMgr.LocalVer[2]);
	gSystemMgr.m_cIICCheckConfigIni.SaveConfigIni(L"IICCheck", L"LocalVer[3]", gSystemMgr.LocalVer[3]);

}


void CIICCheckDlg::OnBnClickedButton1()
{
	//gSystemMgr.imgCTS.read_iic_check();
	switch (gSystemMgr.m_nImageSource)
	{
	case IMG_DEV_CTS:
		gSystemMgr.imgCTS.read_iic_check();
		break;
	case IMG_RO_LONGO:
		gSystemMgr.imgRLG.read_iic_check();
		break;
	}
}
